package com.biscuit.page.basicservice.conf.handler;

import com.alibaba.fastjson.serializer.JSONSerializer;
import com.alibaba.fastjson.serializer.ObjectSerializer;
import org.springframework.web.multipart.commons.CommonsMultipartFile;

import java.io.IOException;
import java.lang.reflect.Type;

/**
 * @author mazihao
 * @createTime 2024/4/1 14:30
 */
public class MultipartFileSerializerHandler implements ObjectSerializer {

    @Override
    public void write(JSONSerializer jsonSerializer, Object o, Object o1, Type type, int i) throws IOException {
        if (o instanceof CommonsMultipartFile) {
            // 在这里定义如何序列化 CommonsMultipartFile 对象
            // 例如，你可以将其转换为字符串形式或者只序列化其中的某些属性
            jsonSerializer.write("CommonsMultipartFile");
        } else {
            jsonSerializer.write(o);
        }
    }

}
